<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>流程设置新增</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
            <div class="fieldBox">
                <div class="label">流程名称</div>
                <div class="field">
                    <input name="procDefName" id="procDefName" type="text" class="ui-textbox" value="">
                    <input name="orgCd" id="orgCd" type="text" style="display: none;" value="${orgCd}">
                    
                </div>
            </div>
            <div class="clearFix"></div>
            <div class="btnsBox">
               <span id="searchBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_1"></i>查询</span>
               <span id="clearBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_19"></i>清空</span>
               <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
            </div>
        </div>
    </form>
</div>
<div id="ligergrid1" class="sq-grid"></div>
<div class="btnsBox" align="center">
     <span id="cust_cst_np_social_rl_form_add_btn_id" class="sq-button l-dialog-btn-ok">保存</span>
     <span id="cust_cst_np_social_rl_form_cancel_btn_id" class="sq-button">取消</span>
</div>
</div>

<script type="text/javascript">
	var grid = null;
	$(function () {
        initGrid();
	    initForm();
	    initEvent();
	});
	
	//初始化Grid
	function initGrid(){
		var modelTypList = [];//模块类型数据
        <c:if test="${not empty modelTypList}">
        	modelTypList = ${modelTypList};
        </c:if>
		 $("#ligergrid1").ligerGrid({
		    	url: '<%=path%>/system/sysflowmanage/initList.do',
		    	method : 'get',
		        columns: [
			            {
			                display: '序号',
			                width: 40,
			                render: function (rowdata, rowindex, value) {
			                    var h=rowindex+1;
			                    return h;
			                }
		            	}, {
		                    display: '流程名称',
		                    name: 'procDefName',
		                    minWidth: 90
		                }, {
		                    display: '流程业务分类',
		                    name: 'modelTyp',
		                    width: 90,
		                    editor: { type: 'select' , data: modelTypList, valueField: 'key', textField:'value'}	
		                }, {
		                    display: '版本数量',
		                    name: 'procDefVersNum',
		                    width: 60
		                }, {
		                    display: '启用版本名称',
		                    name: 'useVersNm',
		                    minWidth: 90,
		                }, {
		                    display: '流程状态',
		                    name: 'isValidNm',
		                    width: 60,
		                    render: function (rowdata, rowindex, value) {
		                    	if(rowdata.isValid == 1){
		                    		return LogUtils.LOG_CMM_GRID_BTN_ENABLE;
		                    	}else if(rowdata.isValid == 0){
		                    		return LogUtils.LOG_CMM_GRID_BTN_DISABLE;
		                    	}
		                    }
		                }
		            
		        ],
	            onBeforeSubmitEdit: function (e) {//重新赋值,要不然选中后离开会把key显示在前端
	                if (e.selected && e.column.columnname == "modelTyp") {
	                    e.record.modelTypId = e.value;
	                    e.value = e.selected[e.column.editor.textField];
	                }
	            },
		        pageSize:10,
		        root:'rows',
		        record:'total',
		        checkbox: true,
		        hideLoadButton : true,
		        width: '100%',
		        height:'100%',
		        heightDiff:-2,
		        enabledEdit: true,
		        rownumbers:false
		    });
		    //赋值Grid
		    grid = liger.get("ligergrid1");
		    grid.setHeight(100);
	}
	
	//初始查询form
	function initForm(){
	    $("#searchBar").ligerForm();
	}
	
	//初始化事件
	function initEvent(){
		 $("#cust_cst_np_social_rl_form_add_btn_id").click(function(event) {
			 	//设置组织架构代码
	            var _orgCd = $("#orgCd").val();
			 	if(StringUtils.isEmpty(_orgCd)){
			 		UIUtils.alertWarning("组织架构代码不能为空!");
			 		return;
			 	}
			 	
	            var _grid = grid.getSelectedRows();
	            if(_grid.length == 0){
	            	UIUtils.alertWarning(LogUtils.LOG_CMM_SELECT_MORE_ROW);
	    			return;
	    		}
	    		var _data = [];
	    		var pass = true;
	    		var validNm = "";
	    		for ( var index in _grid) {
	    			if(!_grid[index].modelTypId){
	    				pass = false;
	    				validNm = _grid[index].procDefName;
	    				break;
	    			}
	    			var obj = {};
	    			obj["id"] = _grid[index].id;
	    			obj["procDefKey"] = _grid[index].procDefKey;
	    			obj["modelTyp"] = _grid[index].modelTypId;
	    			obj["orgCd"] = _orgCd;
	    			_data.push(obj);
	    		}
	    		
	    		if(!pass){
	    			UIUtils.alertWarning("请填写["+validNm+"]流程模块类型");
	    			return;
	    		}
	            var _url = '<%=path%>/system/sysflowmanageorgr/modify.do';
	            AjaxUtils.ajaxPost(_url, {data:JSON.stringify(_data)}, function(msg){
	            	if(msg.success == 1){
	            		 UIUtils.alertSuccess(msg.info);
	       				 parent.reloadGrid();
	       				 frameElement.dialog.close();
	       			 }else{
	       				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	       			 }
	            },true);
	        });
		 
			//取消
	        $("#cust_cst_np_social_rl_form_cancel_btn_id").click(function(event) {
	        	frameElement.dialog.close();
	        });
			
	      	//查询按钮
		    $("#searchBtn").click(function(event) {
		    	reloadGrid();
		    });
			
		    $("#clearBtn").click(function(event) {
		        $("#resetBtn").click();  //重置 input-text
		    });
	}
	
	//带条件重载Grid
	function reloadGrid(){
		 var form = new liger.get("searchBar");
         var data = form.getData();
         //alert(JSON.stringify(data));
         for (name in data){
            grid.setParm(name,data[name]);
         };
         grid.reload();
	}
</script>
</body>
</html>